#ifndef F_CASsiDriverC_h
#define F_CASsiDriverC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMCASsiDriverSignal { EDROOMSignalTimeout, EDROOMSignalDestroy, SDataFrame, SSignalFrame, SMsgCommited };


	friend class CASsiDriver;

	CASsiDriver &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Ports

	CEDROOMInterface & SsiFromComponent;

	enum edroomStateId{I, Listening};

	enum IdTrans{Init, SendData, SendSignal, NotDownAnswer,  EDROOMMEMORIA };

	//Constantes



	//Variables

	uint16_t &VByteNumber;
	bool_t &VMessageCompleted;
	byte_t *VStringDataBurst;


	//Pool

	class CEDROOMPOOLCDFrame:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDFrame(TEDROOMUInt32 elemCount,CDFrame *pMem, TEDROOMBool *pMarks);
		CDFrame	* AllocData();
	};
	CEDROOMPOOLCDFrame	& EDROOMPoolCDFrame;
	class CEDROOMPOOLCDSignal:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDSignal(TEDROOMUInt32 elemCount,CDSignal *pMem, TEDROOMBool *pMarks);
		CDSignal	* AllocData();
	};
	CEDROOMPOOLCDSignal	& EDROOMPoolCDSignal;


	// CONSTRUCTORES

	EDROOMTopContext (CASsiDriver &act, uint16_t & EDROOMpVarVByteNumber, bool_t & EDROOMpVarVMessageCompleted, byte_t * EDROOMpVarVStringDataBurst, CEDROOMPOOLCDFrame & EDROOMpPoolCDFrame, CEDROOMPOOLCDSignal & EDROOMpPoolCDSignal );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	void	FBuildUpFrame();

	void	FCheckBytesReceived();

	void	FGetData();

	void	FInit();

	void	FSendDataFrameToGround();

	void	FSendSignalFrameToGround();

	void	FWaitToResponse();

};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:



	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	uint16_t VByteNumber;
	bool_t VMessageCompleted;
	byte_t VStringDataBurst[50];


	//Pools

	CEDROOMPOOLCDFrame	EDROOMPoolCDFrame;
	CEDROOMPOOLCDSignal	EDROOMPoolCDSignal;


public:

	// CONSTRUCTOR

	EDROOMTopState (CASsiDriver &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Listening

	// ***********************************************************************



	TEDROOMTransId EDROOMListeningllegada();

};


#endif
